<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('分工分配')}:</label>
        <div class="col-xs-12 col-sm-8">
            <select id="c-allocation_id" class="form-control selectpicker" name="row[allocation_id]" data-rule="required">
                <option value="">{:__('请选择')}</option>
            </select>
        </div>
    </div>
    
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('工作类型')}:</label>
        <div class="col-xs-12 col-sm-8">
            <select id="c-work_type" class="form-control selectpicker" name="row[work_type]">
                <option value="piece">计件</option>
                <option value="time">计时</option>
            </select>
        </div>
    </div>
    
    <div class="form-group piece-work" style="display:none;">
        <label class="control-label col-xs-12 col-sm-2">{:__('产品编号')}:</label>
        <div class="col-xs-12 col-sm-8">
            <div id="item-list" class="checkbox-group">
                {volist name="items" id="item"}
                    <label class="checkbox-inline">
                        <input type="checkbox" name="row[item_nos][]" value="{$item.item_no}"> {$item.item_no}
                    </label>
                {/volist}
            </div>
        </div>
    </div>
    
    <div class="form-group time-work" style="display:none;">
        <label class="control-label col-xs-12 col-sm-2">{:__('工时')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-work_hours" class="form-control" name="row[work_hours]" type="number" step="0.5" min="0">
        </div>
    </div>
    
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('备注')}:</label>
        <div class="col-xs-12 col-sm-8">
            <textarea id="c-remark" class="form-control" name="row[remark]" rows="3"></textarea>
        </div>
    </div>
    
    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
        </div>
    </div>
</form>

<script>
$(function() {
    // 工作类型切换
    $('#c-work_type').change(function() {
        var workType = $(this).val();
        if (workType == 'piece') {
            $('.piece-work').show();
            $('.time-work').hide();
        } else {
            $('.piece-work').hide();
            $('.time-work').show();
        }
    });
    
    // 分工分配选择变化时加载产品编号
    $('#c-allocation_id').change(function() {
        var allocationId = $(this).val();
        if (allocationId) {
            $.get('scanwork/product_item/get_item_list', {allocation_id: allocationId, status: 0}, function(data) {
                if (data.code == 1) {
                    var html = '';
                    $.each(data.data, function(i, item) {
                        html += '<label class="checkbox-inline">';
                        html += '<input type="checkbox" name="row[item_nos][]" value="' + item.item_no + '"> ' + item.item_no;
                        html += '</label>';
                    });
                    $('#item-list').html(html);
                }
            });
        }
    });
    
    // 表单验证
    Form.api.bindevent($("form[role=form]"));
});
</script>
